From 71d2fbe9779747f67c5c8e50de35cc9a97beb32c Mon Sep 17 00:00:00 2001 From: "emellor@ewan" Date: Sat, 24 Sep 2005 23:10:31 +0100 Subject: [PATCH] Add helper method XendDomain.callInfo that stubs through into XendDomainInfo. This is used to remove much of the code duplication in the public methods there. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/XendDomain.py | 128 +++++++++--------------- tools/python/xen/xend/XendDomainInfo.py | 13 +++ 2 files changed, 60 insertions(+), 81 deletions(-) diff --git a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py index 69b971b536..3174344fc3 100644 --- a/tools/python/xen/xend/XendDomain.py +++ b/tools/python/xen/xend/XendDomain.py @@ -433,12 +433,11 @@ class XendDomain: self.domain_shutdowns() return val + def domain_sysrq(self, id, key): - """Send a SysRq to a domain - """ - dominfo = self.domain_lookup(id) - val = dominfo.send_sysrq(key) - return val + """Send a SysRq to the specified domain.""" + return self.callInfo(id, XendDomainInfo.send_sysrq, key) + def domain_shutdowns(self): """Process pending domain shutdowns. @@ -630,73 +629,45 @@ class XendDomain: except Exception, ex: raise XendError(str(ex)) - def domain_device_create(self, id, devconfig): - """Create a new device for a domain. - @param id: domain id - @param devconfig: device configuration + def domain_device_create(self, domid, devconfig): + """Create a new device for the specified domain. """ - dominfo = self.domain_lookup(id) - val = dominfo.device_create(devconfig) - dominfo.exportToDB() - return val + return self.callInfo(domid, XendDomainInfo.device_create, devconfig) - def domain_device_configure(self, id, devconfig, devid): - """Configure an existing device for a domain. - @param id: domain id - @param devconfig: device configuration - @param devid: device id + def domain_device_configure(self, domid, devconfig, devid): + """Configure an existing device in the specified domain. @return: updated device configuration """ - dominfo = self.domain_lookup(id) - val = dominfo.device_configure(devconfig, devid) - dominfo.exportToDB() - return val - - def domain_device_refresh(self, id, type, devid): - """Refresh a device. + return self.callInfo(domid, XendDomainInfo.device_configure, + devconfig, devid) - @param id: domain id - @param devid: device id - @param type: device type - """ - dominfo = self.domain_lookup(id) - val = dominfo.device_refresh(type, devid) - dominfo.exportToDB() - return val + + def domain_device_refresh(self, domid, devtype, devid): + """Refresh a device.""" + return self.callInfo(domid, XendDomainInfo.device_refresh, devtype, + devid) - def domain_device_destroy(self, id, type, devid): - """Destroy a device. - @param id: domain id - @param devid: device id - @param type: device type - """ - dominfo = self.domain_lookup(id) - return dominfo.destroyDevice(type, devid) + def domain_device_destroy(self, domid, devtype, devid): + """Destroy a device.""" + return self.callInfo(domid, XendDomainInfo.destroyDevice, devtype, + devid) - def domain_devtype_ls(self, id, type): - """Get list of device sxprs for a domain. + def domain_devtype_ls(self, domid, devtype): + """Get list of device sxprs for the specified domain.""" + return self.callInfo(domid, XendDomainInfo.getDeviceSxprs, devtype) - @param id: domain - @param type: device type - @return: device sxprs - """ - dominfo = self.domain_lookup(id) - return dominfo.getDeviceSxprs(type) - def domain_devtype_get(self, id, type, devid): + def domain_devtype_get(self, domid, devtype, devid): """Get a device from a domain. - @param id: domain - @param type: device type - @param devid: device id @return: device object (or None) """ - dominfo = self.domain_lookup(id) - return dominfo.getDevice(type, devid) + return self.callInfo(domid, XendDomainInfo.getDevice, devtype, devid) + def domain_vif_limit_set(self, id, vif, credit, period): """Limit the vif's transmission rate @@ -723,7 +694,7 @@ class XendDomain: """Set the memory limit for a domain. @param id: domain - @param mem: memory limit (in MB) + @param mem: memory limit (in MiB) @return: 0 on success, -1 on error """ dominfo = self.domain_lookup(id) @@ -734,42 +705,37 @@ class XendDomain: except Exception, ex: raise XendError(str(ex)) - def domain_mem_target_set(self, id, mem): + def domain_mem_target_set(self, domid, mem): """Set the memory target for a domain. - @param id: domain - @param mem: memory target (in MB) - @return: 0 on success, -1 on error + @param mem: memory target (in MiB) """ - dominfo = self.domain_lookup(id) - return dominfo.setMemoryTarget(mem << 10) + self.callInfo(domid, XendDomainInfo.setMemoryTarget, mem << 10) - def domain_vcpu_hotplug(self, id, vcpu, state): - """Enable or disable VCPU vcpu in DOM id - @param id: domain + def domain_vcpu_hotplug(self, domid, vcpu, state): + """Enable or disable specified VCPU in specified domain + @param vcpu: target VCPU in domain @param state: which state VCPU will become - @return: 0 on success, -1 on error """ + self.callInfo(domid, XendDomainInfo.vcpu_hotplug, vcpu, state) - dominfo = self.domain_lookup(id) - return dominfo.vcpu_hotplug(vcpu, state) - def domain_dumpcore(self, id): - """Save a core dump for a crashed domain. + def domain_dumpcore(self, domid): + """Save a core dump for a crashed domain.""" + self.callInfo(domid, XendDomainInfo.dumpCore) + + + ## private: + + def callInfo(self, domid, fn, *args, **kwargs): + self.refresh() + dominfo = self.domains.get(domid) + if dominfo: + return fn(dominfo, *args, **kwargs) + - @param id: domain - """ - dominfo = self.domain_lookup(id) - corefile = "/var/xen/dump/%s.%s.core" % (dominfo.getName(), - dominfo.getDomid()) - try: - xc.domain_dumpcore(dom=dominfo.getDomid(), corefile=corefile) - except Exception, ex: - log.warning("Dumpcore failed, id=%s name=%s: %s", - dominfo.getDomid(), dominfo.getName(), ex) - def instance(): """Singleton constructor. Use this instead of the class constructor. """ diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 708d2cf53b..70c8755507 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -513,6 +513,19 @@ class XendDomainInfo: self.info['backend'], 0) + def dumpCore(self): + """Create a core dump for this domain. Nothrow guarantee.""" + + try: + corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'], + self.domid) + xc.domain_dumpcore(dom = self.domid, corefile = corefile) + + except Exception, exn: + log.error("XendDomainInfo.dumpCore failed: id = %s name = %s: %s", + self.domid, self.info['name'], str(exn)) + + def closeStoreChannel(self): """Close the store channel, if any. Nothrow guarantee.""" -- 2.30.2